﻿namespace CSharpPro2._1016;

public class Demo
{
    public class TestPrint1
    {
        //作业1
        public static void Test1()
        {
            Console.Write("请输入整数x: ");
            int x = int.Parse(Console.ReadLine());
            Console.Write("请输入整数y: ");
            int y = int.Parse(Console.ReadLine());
            Console.Write("请输入整数z: ");
            int z = int.Parse(Console.ReadLine());

            int[] num = new int[3];
            num[0] = x;
            num[1] = y;
            num[2] = z;
            for (int i = 0; i < num.Length; i++)
            {
                for (int j = i + 1; j < num.Length; j++)
                {
                    if (num[i] > num[j])
                    {
                        int temp = num[i];
                        num[i] = num[j];
                        num[j] = temp;
                    }
                }
            }

            Console.WriteLine($"由小到大排序: {num[0]}, {num[1]}, {num[2]}");
        }

        //作业2
        public static void Test2()
        {
            int sum = 0;
            for (int i = 1; i <= 100; i++)
            {
                if (i % 7 != 0 && i / 10 != 7 && i % 10 != 7)
                {
                    Console.WriteLine($"{i}");
                    sum += i;
                }
            }

            Console.WriteLine("\n总和为:" + sum);
        }

        //作业3
        public static void Test3()
        {
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= 9; j++)
                {
                    Console.Write($"{i}*{j}={i * j} ");
                }

                Console.WriteLine();
            }
        }

        //作业4
        public static void Test4()
        {
            List<int> perfectNumbers = new List<int>();
            for (int num = 2; num <= 1000; num++)
            {
                int factorSum = 1;
                for (int i = 2; i <= Math.Sqrt(num); i++)
                {
                    if (num % i == 0)
                    {
                        factorSum += i;
                    
                        int otherFactor = num / i;
                        if (otherFactor != i) 
                        {
                            factorSum += otherFactor;
                        }
                    }
                }
                if (factorSum == num)
                {
                    perfectNumbers.Add(num);
                }
            }
            Console.WriteLine("1000以内的完数有：");
            Console.WriteLine(string.Join(", ", perfectNumbers));
        }

        //作业5
        public static void Test5()
        {
            Console.WriteLine("请输入一个正整数: ");
            int number = int.Parse(Console.ReadLine());

            int Count = 0;
            int reversed = 0;

            while (number > 0)
            {
                int last = number % 10;
                Count++;
                reversed = reversed * 10 + last;
                number /= 10;
            }

            Console.WriteLine($"这个正整数是 {Count} 位数");
            Console.WriteLine($"逆序打印各位数字: {reversed}");
        }

        //作业6
        public static void Test6()
        {
            Console.WriteLine("请输入菱形的行数：");
            int rows = int.Parse(Console.ReadLine());
            int m = rows / 2;

            for (int i = 0; i <= m; i++)
            {
                for (int j = 0; j < m - i; j++)
                    Console.Write(" ");
                for (int k = 0; k < 2 * i + 1; k++)
                    Console.Write("*");
                Console.WriteLine();
            }
            for (int i = m - 1; i >= 0; i--)
            {
                for (int j = 0; j < m - i; j++)
                    Console.Write(" ");
                for (int k = 0; k < 2 * i + 1; k++)
                    Console.Write("*");
                Console.WriteLine();
            }
        }
    }
}
